import React, { Component } from "react";
import { Form, Input, Select } from "antd";
import PropTypes from "prop-types";
const { Option } = Select;

class AddFrom extends Component {
  static propTypes = {
    categorys: PropTypes.array.isRequired,
    parentId: PropTypes.string.isRequired,
    getForm: PropTypes.func.isRequired,
  };

  componentDidMount() {
    const { getForm, form } = this.props;
    getForm(form);
  }

  render() {
    const { categorys, parentId } = this.props;
    const { getFieldDecorator } = this.props.form;

    return (
      <Form>
        <Form.Item>
          <span style={{ color: "black" }}>所属分类：</span>
          {getFieldDecorator("parentId", {
            initialValue: parentId,
          })(
            <Select size={"default"}>
              <Option key={0} value="0">
                一级分类
              </Option>
              {categorys.map((c) => (
                <Option key={c._id} value={c._id}>
                  {c.name}
                </Option>
              ))}
            </Select>
          )}
        </Form.Item>
        <Form.Item>
          <span style={{ color: "black" }}>分类名称：</span>
          {getFieldDecorator("addCategoryName", {
            initialValue: "",
            rules: [{ required: true, message: "分类名称必须输入" }],
          })(<Input placeholder="请输入分类名称" />)}
        </Form.Item>
      </Form>
    );
  }
}
export default Form.create()(AddFrom);
